package com.clz.appdesign.myapp.media;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.widget.MediaController;
import android.widget.VideoView;

import com.blankj.utilcode.util.LogUtils;
import com.clz.appdesign.appdependence.base.BaseActivity;
import com.clz.appdesign.myapp.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author
 */
public class VideoActivity extends BaseActivity {

    @BindView(R.id.video_view)
    VideoView mVideoView;

    @Override
    public void initToolbar() {
        ButterKnife.bind(this);
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {

    }

    @Override
    public void doBusiness(Context mContext) {
        videoPlayByLocal();
        //VideoPlayByVideoView();
        videoPlayByMediaPlayer();
    }

    private void videoPlayByMediaPlayer() {

    }

    private void VideoPlayByVideoView() {
        Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/video.mp4");
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.setVideoURI(uri);
        mVideoView.start();
        mVideoView.requestFocus();
    }

    /**
     * 调用系统自带的播放器
     */
    private void videoPlayByLocal() {
        Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/video.mp4");
        Intent intent = new Intent(Intent.ACTION_VIEW);
        LogUtils.d(uri.toString());
        intent.setDataAndType(uri, "video/mp4");
        startActivity(intent);
    }

    @Override
    public int layoutResID() {
        return R.layout.activity_video;
    }
}
